package com.pj.wisdomlogistics.mvp.presenter;

import android.text.TextUtils;

import com.pj.wisdomlogistics.entity.User;
import com.pj.wisdomlogistics.entity.VersionEntity;
import com.pj.wisdomlogistics.mvp.contract.SplashContract;
import com.pj.wisdomlogistics.mvp.frame.ActivityPresenter;
import com.pj.wisdomlogistics.mvp.model.SplashModel;
import com.pj.wisdomlogistics.rx.FilterSubscriber;
import com.pj.wisdomlogistics.utils.Log;


public class SplashPresenter extends ActivityPresenter<SplashModel,SplashContract.View> implements SplashContract.Presenter {
    @Override
    public void checkLogin(String accessToken) {
        if (TextUtils.isEmpty(accessToken)) {
            getView().onError(0,"" , "checkLogin");
            return;
        }

        addSubscription(getModel().checkLogin(accessToken), new FilterSubscriber<User>() {
            @Override
            public void onNext(User mUser) {
                getView().showCheckResult(mUser);
            }

            @Override
            public void onError(int errorCode, String errorMsg) {
                getView().onError(errorCode , errorMsg , "checkLogin");
            }

        });

    }

    @Override
    public void checkVersion() {
        addSubscription(getModel().checkVersion(), new FilterSubscriber<VersionEntity>() {
            @Override
            public void onNext(VersionEntity mVersionEntity) {
                getView().showVersion(mVersionEntity);
            }

            @Override
            public void onError(int errorCode, String errorMsg) {
                getView().onError(errorCode , errorMsg , "checkVersion" + errorCode + errorMsg);
            }

        });
    }


    @Override
    public void login(String username, String password) {
        addSubscription(getModel().login(username, password), new FilterSubscriber<User>() {
            @Override
            public void onNext(User mUser) {
                getView().showLoginSuccess(mUser);
            }

            @Override
            public void onError(int errorCode, String errorMsg) {
                getView().onError(errorCode , errorMsg , "login");
            }

        });
    }

    @Override
    public void login_jc(String username) {
        addSubscription(getModel().login_jc(username), new FilterSubscriber<User>() {
            @Override
            public void onNext(User mUser) {
                getView().showLoginSuccess(mUser);
            }

            @Override
            public void onError(int errorCode, String errorMsg) {
                getView().onError(errorCode , errorMsg , "login_jc");
            }


        });
    }

}
